package com.example.demo;

public class IntersectionNodeDemo {

    public static void main(String[] args) {

    }
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode temp=headA;

        while (temp!=null){
               temp =temp.next;
               while (headB!=null){
                   if(temp==headB){
                      return temp;
                   }
               }
        }
       return null;
    }
    public class ListNode {
      int val;
      ListNode next;
     ListNode(int x) {
          val = x;
          next = null;
     }
  }
}
